﻿using System;
using NUnit.Framework;

namespace InvoiceInvoker.Logic.Tests
{
	[TestFixture]
	public class PdfCreatorTests
	{
		[Test]
		public void CreatesNormalInvoice()
		{
			Invoice invoice = new Invoice();
			Seller seller = new Seller();
			Customer customer = new Customer();
			Product product1 = new Product();
			Product product2 = new Product();

			invoice.CreationDate = new DateTime(2010, 8, 30);
			invoice.LeftToPay = 40.80M;
			invoice.Number = "1/8/2010";
			invoice.Paid = 10.10M;
			invoice.PaymentCurrency = "PLN";
			invoice.PaymentDeadline = new DateTime(2010, 9, 14);
			invoice.PaymentType = "Przelew";
			invoice.Remarks = "SomeNormalRemarks";
			invoice.SaleDate = new DateTime(2010, 8, 31);
			invoice.ToPay = 50.90M;
			invoice.ToPayInWords = "pięćdziesiąt PLN 90/100";

			seller.BankAccountNumber = "0000-1111-2222-3333-4444-5555";
			seller.BankName = "TestBankName";
			seller.BankSwift = "TBN";
			seller.City = "SomeNormalCityName";
			seller.CompanyName = "SomeNormalCompanyName";
			seller.Nip = "0123456789";
			seller.PostalCode = "12-345";
			seller.SellerName = "SomeNormalSellerName";
			seller.Street = "SomeNormalStreetName";

			customer.City = "AnotherNormalCityName";
			customer.CompanyName = "AnotherNormalCompanyName";
			customer.CustomerName = "SomeNormalCustomerName";
			customer.Nip = "9876543210";
			customer.PostalCode = "54-321";
			customer.Street = "AnotherNormalStreetName";

			product1.GrossValue = 10.10M;
			product1.MeasureUnit = "szt.";
			product1.Name = "ProductOfNormalName1";
			product1.NetPrice = 10.00M;
			product1.NetValue = 10.00M;
			product1.Pkwiu = "12.34.56";
			product1.Quantity = 1.0M;
			product1.VatRate = "1%";
			product1.VatValue = 0.10M;

			product2.GrossValue = 40.80M;
			product2.MeasureUnit = "l";
			product2.Name = "ProductOfNormalName2";
			product2.NetPrice = 20.00M;
			product2.NetValue = 40.00M;
			product2.Pkwiu = "65.43.21";
			product2.Quantity = 2.0M;
			product2.VatRate = "2%";
			product2.VatValue = 0.80M;

			invoice.Seller = seller;
			invoice.Customer = customer;
			invoice.Products.Add(product1);
			invoice.Products.Add(product2);

			PdfCreator creator = new PdfCreator(invoice);
			creator.Create(PdfCreator.InvoiceType.Preview);
			creator.SaveDocument("test_CreatesNormalInvoice.pdf", true);
		}

		[Test]
		public void HandlesVeryLongStrings()
		{
			Invoice invoice = new Invoice();
			Seller seller = new Seller();
			Customer customer = new Customer();
			Product product1 = new Product();
			Product product2 = new Product();

			invoice.CreationDate = new DateTime(2010, 8, 30);
			invoice.LeftToPay = 9999999999.99M;
			invoice.Number = "___...:::...___00001___...:::...___08___...:::...___2010___...:::...___";
			invoice.Paid = 9999999999.99M;
			invoice.PaymentCurrency = "PLN";
			invoice.PaymentDeadline = new DateTime(2010, 9, 14);
			invoice.PaymentType = "Przelew";
			invoice.Remarks = "Some ";
			for (int i = 0; i != 100; i++) invoice.Remarks += "very ";
			invoice.Remarks += "long remarks.";
			invoice.SaleDate = new DateTime(2010, 8, 31);
			invoice.ToPay = 9999999999.99M;
			invoice.ToPayInWords = "Some ";
			for (int i = 0; i != 50; i++) invoice.ToPayInWords += "very ";
			invoice.ToPayInWords += "large amount beyond anyone's dreams";

			seller.BankAccountNumber = "0000-1111-2222-3333-4444-5555";
			seller.BankName = "TestBankName";
			seller.BankSwift = "TBN";
			seller.City = "SomeNormalCityName";
			seller.CompanyName = "SomeNormalCompanyName";
			seller.Nip = "0123456789";
			seller.PostalCode = "12-345";
			seller.SellerName = "SomeNormalSellerName";
			seller.Street = "SomeNormalStreetName";

			customer.City = "SomeVeryVeryVeryVeryVeryVeryVeryVeryLongCityName";
			customer.CompanyName = "SomeVeryVeryVeryVeryVeryVeryVeryVeryLongCompanyName";
			customer.CustomerName = "SomeVeryVeryVeryVeryVeryVeryVeryVeryLongCustomerNameUlmishProbably";
			customer.Nip = "9876543210";
			customer.PostalCode = "54-321";
			customer.Street = "SomeVeryVeryVeryVeryVeryVeryVeryVeryLongStreetName";

			invoice.Seller = seller;
			invoice.Customer = customer;

			for (int i = 0; i != 5; i++)
			{
				Product product = new Product();
				product.GrossValue = 1000000000.00M;
				product.MeasureUnit = "l";
				product.Name = "ProductOfVeryVeryVeryVeryVeryLongName" + (i + 1).ToString();
				product.NetPrice = 1000000000.00M;
				product.NetValue = 1000000000.00M;
				product.Pkwiu = "11.10.98.76.54.32.10";
				product.Quantity = 1000000.00M;
				product.VatRate = "1%";
				product.VatValue = 1000000000.00M;
				invoice.Products.Add(product);
			}

			for (int i = 0; i != 5; i++)
			{
				Product product = new Product();
				product.GrossValue = 2000000000.00M;
				product.MeasureUnit = "l";
				product.Name = "ProductOfVeryVeryVeryVeryVeryLongName" + (i + 6).ToString();
				product.NetPrice = 2000000000.00M;
				product.NetValue = 2000000000.00M;
				product.Pkwiu = "11.10.98.76.54.32.10";
				product.Quantity = 2000000.00M;
				product.VatRate = "2%";
				product.VatValue = 2000000000.00M;
				invoice.Products.Add(product);
			}

			for (int i = 0; i != 5; i++)
			{
				Product product = new Product();
				product.GrossValue = 3000000000.00M;
				product.MeasureUnit = "l";
				product.Name = "ProductOfVeryVeryVeryVeryVeryLongName" + (i + 11).ToString();
				product.NetPrice = 3000000000.00M;
				product.NetValue = 3000000000.00M;
				product.Pkwiu = "11.10.98.76.54.32.10";
				product.Quantity = 3000000.00M;
				product.VatRate = "3%";
				product.VatValue = 3000000000.00M;
				invoice.Products.Add(product);
			}

			for (int i = 0; i != 5; i++)
			{
				Product product = new Product();
				product.GrossValue = 4000000000.00M;
				product.MeasureUnit = "l";
				product.Name = "ProductOfVeryVeryVeryVeryVeryLongName" + (i + 16).ToString();
				product.NetPrice = 4000000000.00M;
				product.NetValue = 4000000000.00M;
				product.Pkwiu = "11.10.98.76.54.32.10";
				product.Quantity = 4000000.00M;
				product.VatRate = "4%";
				product.VatValue = 4000000000.00M;
				invoice.Products.Add(product);
			}

			for (int i = 0; i != 5; i++)
			{
				Product product = new Product();
				product.GrossValue = 5000000000.00M;
				product.MeasureUnit = "l";
				product.Name = "ProductOfVeryVeryVeryVeryVeryLongName" + (i + 21).ToString();
				product.NetPrice = 5000000000.00M;
				product.NetValue = 5000000000.00M;
				product.Pkwiu = "11.10.98.76.54.32.10";
				product.Quantity = 5000000.00M;
				product.VatRate = "5%";
				product.VatValue = 5000000000.00M;
				invoice.Products.Add(product);
			}

			for (int i = 0; i != 5; i++)
			{
				Product product = new Product();
				product.GrossValue = 6000000000.00M;
				product.MeasureUnit = "l";
				product.Name = "ProductOfVeryVeryVeryVeryVeryLongName" + (i + 26).ToString();
				product.NetPrice = 6000000000.00M;
				product.NetValue = 6000000000.00M;
				product.Pkwiu = "11.10.98.76.54.32.10";
				product.Quantity = 6000000.00M;
				product.VatRate = "6%";
				product.VatValue = 6000000000.00M;
				invoice.Products.Add(product);
			}

			for (int i = 0; i != 5; i++)
			{
				Product product = new Product();
				product.GrossValue = 7000000000.00M;
				product.MeasureUnit = "l";
				product.Name = "ProductOfVeryVeryVeryVeryVeryLongName" + (i + 31).ToString();
				product.NetPrice = 7000000000.00M;
				product.NetValue = 7000000000.00M;
				product.Pkwiu = "11.10.98.76.54.32.10";
				product.Quantity = 7000000.00M;
				product.VatRate = "7%";
				product.VatValue = 7000000000.00M;
				invoice.Products.Add(product);
			}

			PdfCreator creator = new PdfCreator(invoice);
			creator.Create(PdfCreator.InvoiceType.Preview);
			creator.SaveDocument("test_HandlesVeryLongStrings.pdf", true);
		}

		[Test]
		public void SplitsProducts()
		{
			Invoice invoice = new Invoice();
			Seller seller = new Seller();
			Customer customer = new Customer();

			invoice.CreationDate = new DateTime(2010, 8, 30);
			invoice.LeftToPay = 10.10M;
			invoice.Number = "1/8/2010";
			invoice.Paid = 100.10M;
			invoice.PaymentCurrency = "PLN";
			invoice.PaymentDeadline = new DateTime(2010, 9, 14);
			invoice.PaymentType = "Przelew";
			invoice.Remarks = "TestRemarks";
			invoice.SaleDate = new DateTime(2010, 8, 31);
			invoice.ToPay = 110.20M;
			invoice.ToPayInWords = "TestToPayInWords";

			seller.BankAccountNumber = "0000-1111-2222-3333-4444-5555";
			seller.BankName = "TestBankName";
			seller.BankSwift = "TBN";
			seller.City = "TestCity";
			seller.CompanyName = "TestCompany";
			seller.Nip = "0123456789";
			seller.PostalCode = "12-345";
			seller.SellerName = "TestSeller";
			seller.Street = "TestStreet";

			customer.City = "TestCity";
			customer.CompanyName = "TestCompany";
			customer.CustomerName = "TestCustomer";
			customer.Nip = "9876543210";
			customer.PostalCode = "54-321";
			customer.Street = "TestStreet";

			for (int i = 0; i != 51; i++)
			{
				Product product = new Product();
				product.GrossValue = 12.34M;
				product.MeasureUnit = "szt.";
				product.Name = "TestProduct" + (i + 1).ToString();
				product.NetPrice = 12.34M;
				product.NetValue = 12.34M;
				product.Pkwiu = "12.34.56";
				product.Quantity = 12.34M;
				product.VatRate = "1%";
				product.VatValue = 12.34M;
				invoice.Products.Add(product);
			}

			invoice.Seller = seller;
			invoice.Customer = customer;

			PdfCreator creator = new PdfCreator(invoice);
			creator.Create(PdfCreator.InvoiceType.Preview);
			creator.SaveDocument("test_SplitsProducts.pdf", true);
		}

		[Test]
		public void SplitsGeneralAmountsInfo()
		{
			Invoice invoice = new Invoice();
			Seller seller = new Seller();
			Customer customer = new Customer();

			invoice.CreationDate = new DateTime(2010, 8, 30);
			invoice.LeftToPay = 10.10M;
			invoice.Number = "1/8/2010";
			invoice.Paid = 100.10M;
			invoice.PaymentCurrency = "PLN";
			invoice.PaymentDeadline = new DateTime(2010, 9, 14);
			invoice.PaymentType = "Przelew";
			invoice.Remarks = "TestRemarks";
			invoice.SaleDate = new DateTime(2010, 8, 31);
			invoice.ToPay = 110.20M;
			invoice.ToPayInWords = "TestToPayInWords";

			seller.BankAccountNumber = "0000-1111-2222-3333-4444-5555";
			seller.BankName = "TestBankName";
			seller.BankSwift = "TBN";
			seller.City = "TestCity";
			seller.CompanyName = "TestCompany";
			seller.Nip = "0123456789";
			seller.PostalCode = "12-345";
			seller.SellerName = "TestSeller";
			seller.Street = "TestStreet";

			customer.City = "TestCity";
			customer.CompanyName = "TestCompany";
			customer.CustomerName = "TestCustomer";
			customer.Nip = "9876543210";
			customer.PostalCode = "54-321";
			customer.Street = "TestStreet";

			for (int i = 0; i != 50; i++)
			{
				Product product = new Product();
				product.GrossValue = 12.34M;
				product.MeasureUnit = "szt.";
				product.Name = "TestProduct" + (i + 1).ToString();
				product.NetPrice = 12.34M;
				product.NetValue = 12.34M;
				product.Pkwiu = "12.34.56";
				product.Quantity = 12.34M;
				product.VatRate = "1%";
				product.VatValue = 12.34M;
				invoice.Products.Add(product);
			}

			invoice.Seller = seller;
			invoice.Customer = customer;

			PdfCreator creator = new PdfCreator(invoice);
			creator.Create(PdfCreator.InvoiceType.Preview);
			creator.SaveDocument("test_SplitsGeneralAmountsInfo.pdf", true);
		}

		[Test]
		public void SplitsPaymentInfo()
		{
			Invoice invoice = new Invoice();
			Seller seller = new Seller();
			Customer customer = new Customer();

			invoice.CreationDate = new DateTime(2010, 8, 30);
			invoice.LeftToPay = 10.10M;
			invoice.Number = "1/8/2010";
			invoice.Paid = 100.10M;
			invoice.PaymentCurrency = "PLN";
			invoice.PaymentDeadline = new DateTime(2010, 9, 14);
			invoice.PaymentType = "Przelew";
			invoice.Remarks = "TestRemarks";
			invoice.SaleDate = new DateTime(2010, 8, 31);
			invoice.ToPay = 110.20M;
			invoice.ToPayInWords = "TestToPayInWords";

			seller.BankAccountNumber = "0000-1111-2222-3333-4444-5555";
			seller.BankName = "TestBankName";
			seller.BankSwift = "TBN";
			seller.City = "TestCity";
			seller.CompanyName = "TestCompany";
			seller.Nip = "0123456789";
			seller.PostalCode = "12-345";
			seller.SellerName = "TestSeller";
			seller.Street = "TestStreet";

			customer.City = "TestCity";
			customer.CompanyName = "TestCompany";
			customer.CustomerName = "TestCustomer";
			customer.Nip = "9876543210";
			customer.PostalCode = "54-321";
			customer.Street = "TestStreet";

			for (int i = 0; i != 48; i++)
			{
				Product product = new Product();
				product.GrossValue = 12.34M;
				product.MeasureUnit = "szt.";
				product.Name = "TestProduct" + (i + 1).ToString();
				product.NetPrice = 12.34M;
				product.NetValue = 12.34M;
				product.Pkwiu = "12.34.56";
				product.Quantity = 12.34M;
				product.VatRate = "1%";
				product.VatValue = 12.34M;
				invoice.Products.Add(product);
			}

			invoice.Seller = seller;
			invoice.Customer = customer;

			PdfCreator creator = new PdfCreator(invoice);
			creator.Create(PdfCreator.InvoiceType.Preview);
			creator.SaveDocument("test_SplitsPaymentInfo.pdf", true);
		}

		[Test]
		public void SplitsRemarks()
		{
			Invoice invoice = new Invoice();
			Seller seller = new Seller();
			Customer customer = new Customer();

			invoice.CreationDate = new DateTime(2010, 8, 30);
			invoice.LeftToPay = 10.10M;
			invoice.Number = "1/8/2010";
			invoice.Paid = 100.10M;
			invoice.PaymentCurrency = "PLN";
			invoice.PaymentDeadline = new DateTime(2010, 9, 14);
			invoice.PaymentType = "Przelew";
			invoice.Remarks = "TestRemarks";
			invoice.SaleDate = new DateTime(2010, 8, 31);
			invoice.ToPay = 110.20M;
			invoice.ToPayInWords = "TestToPayInWords";

			seller.BankAccountNumber = "0000-1111-2222-3333-4444-5555";
			seller.BankName = "TestBankName";
			seller.BankSwift = "TBN";
			seller.City = "TestCity";
			seller.CompanyName = "TestCompany";
			seller.Nip = "0123456789";
			seller.PostalCode = "12-345";
			seller.SellerName = "TestSeller";
			seller.Street = "TestStreet";

			customer.City = "TestCity";
			customer.CompanyName = "TestCompany";
			customer.CustomerName = "TestCustomer";
			customer.Nip = "9876543210";
			customer.PostalCode = "54-321";
			customer.Street = "TestStreet";

			for (int i = 0; i != 39; i++)
			{
				Product product = new Product();
				product.GrossValue = 12.34M;
				product.MeasureUnit = "szt.";
				product.Name = "TestProduct" + (i + 1).ToString();
				product.NetPrice = 12.34M;
				product.NetValue = 12.34M;
				product.Pkwiu = "12.34.56";
				product.Quantity = 12.34M;
				product.VatRate = "1%";
				product.VatValue = 12.34M;
				invoice.Products.Add(product);
			}

			invoice.Seller = seller;
			invoice.Customer = customer;

			PdfCreator creator = new PdfCreator(invoice);
			creator.Create(PdfCreator.InvoiceType.Preview);
			creator.SaveDocument("test_SplitsRemarks.pdf", true);
		}

		[Test]
		public void SplitsSignatures()
		{
			Invoice invoice = new Invoice();
			Seller seller = new Seller();
			Customer customer = new Customer();

			invoice.CreationDate = new DateTime(2010, 8, 30);
			invoice.LeftToPay = 10.10M;
			invoice.Number = "1/8/2010";
			invoice.Paid = 100.10M;
			invoice.PaymentCurrency = "PLN";
			invoice.PaymentDeadline = new DateTime(2010, 9, 14);
			invoice.PaymentType = "Przelew";
			invoice.Remarks = "TestRemarks";
			invoice.SaleDate = new DateTime(2010, 8, 31);
			invoice.ToPay = 110.20M;
			invoice.ToPayInWords = "TestToPayInWords";

			seller.BankAccountNumber = "0000-1111-2222-3333-4444-5555";
			seller.BankName = "TestBankName";
			seller.BankSwift = "TBN";
			seller.City = "TestCity";
			seller.CompanyName = "TestCompany";
			seller.Nip = "0123456789";
			seller.PostalCode = "12-345";
			seller.SellerName = "TestSeller";
			seller.Street = "TestStreet";

			customer.City = "TestCity";
			customer.CompanyName = "TestCompany";
			customer.CustomerName = "TestCustomer";
			customer.Nip = "9876543210";
			customer.PostalCode = "54-321";
			customer.Street = "TestStreet";

			for (int i = 0; i != 32; i++)
			{
				Product product = new Product();
				product.GrossValue = 12.34M;
				product.MeasureUnit = "szt.";
				product.Name = "TestProduct" + (i + 1).ToString();
				product.NetPrice = 12.34M;
				product.NetValue = 12.34M;
				product.Pkwiu = "12.34.56";
				product.Quantity = 12.34M;
				product.VatRate = "1%";
				product.VatValue = 12.34M;
				invoice.Products.Add(product);
			}

			invoice.Seller = seller;
			invoice.Customer = customer;

			PdfCreator creator = new PdfCreator(invoice);
			creator.Create(PdfCreator.InvoiceType.Preview);
			creator.SaveDocument("test_SplitsSignatures.pdf", true);
		}
	}
}
